#include "BasicMainWindow.h"

#include <QApplication>
#include <QDesktopWidget>

#ifdef Q_OS_WINDOWS

#include <dwmapi.h>
#include <windows.h>
#include <windowsx.h>

#endif

BasicMainWindow::BasicMainWindow(QWidget *parent) : QMainWindow(parent) {
}

BasicMainWindow::~BasicMainWindow() {
}

void BasicMainWindow::centralize(double r) {
    QWidget *desktop = qApp->desktop();
    if (parentWidget()) {
        desktop = parentWidget();
    }
    int dw = desktop->width();
    int dh = desktop->height();
    if (r > 0 && r <= 1) {
        resize(dw * r, dh * r);
    }
    move(desktop->x() + (dw - width()) / 2, desktop->y() + (dh - height()) / 2);
}

void BasicMainWindow::maximize() {
    setWindowState(Qt::WindowMaximized);
}

void BasicMainWindow::minimize() {
    setWindowState(Qt::WindowMinimized);
}

void BasicMainWindow::normalize() {
    setWindowState(windowState() &
                   ~(Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen));
}

void BasicMainWindow::fullScreen() {
    setWindowState(Qt::WindowFullScreen);
}

void BasicMainWindow::showForward() {
#ifdef Q_OS_WINDOWS
    HWND winId = HWND(this->winId());
    ::SetWindowPos(winId, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
    ::SetWindowPos(winId, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
    show();
    activateWindow();
#endif
}
